package com.game.raceroom.player.effect.skill
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;
	
	import com.util.SwfUtil;
	import com.game.raceroom.player.Player;
	import com.game.raceroom.player.effect.Effect;
	public class RepairEffect extends Effect
	{   
		private var eftText:TextField;
		private var actor:Player;
        private var format:TextFormat= new TextFormat();


		public function RepairEffect(actor:Player,add:int)
		{  
			this.actor=actor;
			this.effectType=EFFECT_TYPE_REPAIR;
			startTime=getTimer();
			maxTime=2000;
			eftText=new TextField;
			eftText.text="+"+add;
       		format.color = 0x04B100;
       		format.size=22;
            format.font = "Bold";               
            eftText.setTextFormat(format);
 
			
			 eftText.x=(80-eftText.width)/2+actor.actorDisp.mc.x;
			eftText.y=actor.actorDisp.mc.y;
			loadMovie();
		    this.actor.actorDisp.addChild(eftText);
		 }
         public function getShowStep():int{
         	var time:int=getTimer()-startTime;
 
         	if(time>maxTime)return 999;
         	else
         	 return time/50;
         	return 0;
         }
         private function zoom(scale:Number):void{
//         	if(this.effectType==EFFECT_TYPE_UNDER_ATK){
//         		
//         	}else
//            if(this.effectType==EFFECT_TYPE_UNDER_FATAL_ATK_L1){
//         		eftText.scaleX=scale;
//         		eftText.scaleY=scale;
//         	}else
//         	if(this.effectType==EFFECT_TYPE_UNDER_FATAL_ATK_L1){
//         		eftText.scaleX=scale+0.5;
//         		eftText.scaleY=scale+0.5;
//         	}else
//         	if(this.effectType==EFFECT_TYPE_UNDER_FATAL_ATK_L1){
//         		eftText.scaleX=scale+1;
//         		eftText.scaleY=scale+1;
//         	}
         }
         private var loadOk:Boolean=false;
         private var frame:int=0;
         public override function update():Boolean{
        	if(loadOk) {
	            mc.x=actor.actorDisp.mc.x+actor.actorDisp.mc.width/2-mc.width/2;
	            mc.y=actor.actorDisp.mc.y+actor.actorDisp.mc.height/2-mc.height/2;
	            mc.gotoAndPlay(frame);
	            frame++;
	            if(frame>=mc.totalFrames){
	            	actor.actorDisp.removeChild(mc);
	            	loadOk=false;
	            }
	        }
 
			eftText.y=actor.actorDisp.mc.y-(getTimer()-startTime)/30;
         	 var step:int=getShowStep();
         	 switch(step){
         	 	case 0:
         	 	   break;
         	 	case 1:
         	 	   zoom(1.1);
         	 	   break;
                case 2:
                   zoom(1.3);
         	 	   break;
                case 4:
                   zoom(1.5);
                   break;
                case 5:
                case 6:
                   zoom(1.8);
         	 	   break;
                case 7:
                   zoom(1.6);
                   break;
                case 8:
                case 9:
                case 10:
                   zoom(1.8);
                   break;
                case 11:
                case 12:
                   zoom(1.5);
         	 	   break;
                case 13:
                   zoom(1.3);
         	 	   break;
                case 14:
                   zoom(1.1);
         	 	   break;
         	    case 999:
         	       actor.actorDisp.removeChild(eftText);
         	       if(actor.actorDisp.contains(mc))
         	       		actor.actorDisp.removeChild(mc);
         	       eftText=null;
         	        valid=false;
         	        break;
         	 }
         	 if(eftText)
         		 eftText.x=(80-eftText.width)/2+actor.actorDisp.mc.x;
        	 return true;
         }
         
        protected var myLoader:Loader;
		public function loadMovie():void{
			myLoader=new Loader();
		    myLoader.contentLoaderInfo.addEventListener(
  	        Event.COMPLETE,function (e:Event):void{initEftOk(e)});
            myLoader.loadBytes(SwfUtil.getEffectSwfStream(SwfUtil.EFT_NAME_REPAIR));
      
		}
		private var mc:MovieClip;
        public function initEftOk(e:Event):void{
            mc = myLoader.content as MovieClip;

            mc.alpha=0.7;
           
			actor.actorDisp.addChild(mc);
			loadOk=true;

        } 
	}
 
}